package com.wlm.service.impl;

import com.wlm.dao.OrderMapper;
import com.wlm.pojo.Order;
import com.wlm.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> findOrders() {
        return orderMapper.findOrders();
    }

    @Override
    public Order findOrderById(Integer id) {
        return orderMapper.findOrderById(id);
    }

    @Override
    public boolean addOrder(Order order) {

        if (order.getOrderTime() == null)
            order.setOrderTime(new java.sql.Date(new java.util.Date().getTime()));
        if (order.getPayTime() == null)
            order.setPayTime(new java.sql.Date(new java.util.Date().getTime() + 30 * 60 * 1000));

        return orderMapper.insertOrder(order) > 0;
    }

    @Override
    public boolean updateOrder(Order order) {
        return orderMapper.updateOrder(order) > 0;
    }

    @Override
    public boolean removeOrderById(Integer id) {
        return orderMapper.removeOrderById(id) > 0;
    }
}
